package com.tqjc.system.common.enums;

import com.sun.org.apache.regexp.internal.RE;
import com.tqjc.system.common.constant.AddTaskConstant;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author 86195
 * @version 1.0
 * @description 天车信息枚举
 * @date 2023/11/13 11:18
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum CarPLCInfoEnum {

    /**
     * PLCInfoArray   大车目标坐标[地址,数据类型,label] 小车目标坐标[]  起升目标坐标[] 作业类型[]  作业地址[] 任务运行[]
     */
    WASTE_STEEL_NO_1("1", AddTaskConstant.WASTE_STEEL_SPAN_NO,1,"1号废钢跨天车","2号废钢跨天车",
            new Object[][]{{"DB8.2.0",4,"1号废钢跨天车大车目标坐标"}, {"DB8.6.0",4,"1号废钢跨天车小车目标坐标"},
                    {"DB8.10.0",4,"1号废钢跨天车起升目标坐标"},{"DB8.0.0",2,"1号废钢跨天车作业类型"},
            {"DB8.14.0",2,"1号废钢跨天车作业地址"},{"DB8.46.0",0,"1号废钢跨天车任务运行"}},CarSafeIndexEnum.WASTE_STEEL_NO_1,"2号废钢跨天车", "1号废钢跨天车枚举"),
    WASTE_STEEL_NO_2("2",AddTaskConstant.WASTE_STEEL_SPAN_NO,2,"2号废钢跨天车","1号废钢跨天车",
            new Object[][]{{"DB8.2.0",4,"2号废钢跨天车大车目标坐标"}, {"DB8.6.0",4,"2号废钢跨天车小车目标坐标"},
                    {"DB8.10.0",4,"2号废钢跨天车起升目标坐标"},{"DB8.0.0",2,"2号废钢跨天车作业类型"},
            {"DB8.14.0",2,"2号废钢跨天车作业地址"},{"DB8.46.0",0,"2号废钢跨天车任务运行"}},CarSafeIndexEnum.WASTE_STEEL_NO_2,"1号废钢跨天车", "2号废钢跨天车枚举"),
    DREGS_STEEL_NO_1("1",AddTaskConstant.DREGS_STEEL_SPAN_NO,3,"1号渣钢跨天车","2号渣钢跨天车",
            new Object[][]{{"DB17.2.0",4,"1号渣钢跨天车大车目标坐标"}, {"DB17.6.0",4,"1号渣钢跨天车小车目标坐标"},
                    {"DB17.10.0",4,"1号渣钢跨天车起升目标坐标"},{"DB17.0.0",2,"1号渣钢跨天车作业类型"},
            {"DB17.14.0",2,"1号渣钢跨天车作业地址"},{"DB17.46.0",0,"1号渣钢跨天车任务运行"}},CarSafeIndexEnum.DREGS_STEEL_NO_1,"2号渣钢跨天车","1号渣钢跨天车枚举"),
    DREGS_STEEL_NO_2("2",AddTaskConstant.DREGS_STEEL_SPAN_NO,4,"2号渣钢跨天车","1号渣钢跨天车",
            new Object[][]{{"DB17.2.0",4,"2号渣钢跨天车大车目标坐标"}, {"DB17.6.0",4,"2号渣钢跨天车小车目标坐标"},
                    {"DB17.10.0",4,"2号渣钢跨天车起升目标坐标"},{"DB17.0.0",2,"2号渣钢跨天车作业类型"},
            {"DB17.14.0",2,"2号渣钢跨天车作业地址"},{"DB17.46.0",0,"2号渣钢跨天车任务运行"}},CarSafeIndexEnum.DREGS_STEEL_NO_2,"1号渣钢跨天车","2号渣钢跨天车枚举");



    /**
     * 天车编码
     */
    private String carNo;

    /**
     * 天车类型   1：废钢跨   2：渣跨
     */
    private String carType;

    /**
     * 扫描编号类型
     */
    private int scanType;



    /**
     *macSN
     */
    private String macSN;

    /**
     * 另一台天车macSN
     */
    private String otherMacSN;

    /**
     * 移动点位信息   大车目标坐标[地址,数据类型,label] 小车目标坐标[]  起升坐标[] 作业类型[]  作业地址[] 任务运行[]
     */
    private Object[][] PLCInfoArray;


    private CarSafeIndexEnum carSafeIndexEnum;


    /**
     * 另外一车的描述
     */
    private String otherDesc;

    /**
     * 天车描述
     */
    private String desc;

    /**
     *
     * @param carType  跨
     * @param carNo    天车编码
     * @return
     */
    public static CarPLCInfoEnum getCarNoEnum(String carType, String carNo){
        for (CarPLCInfoEnum value : values()) {
            if(value.getCarNo().equals(carNo) && value.getCarType().equals(carType)){
                return value;
            }

        }
        return null;

    }


    public static boolean  checkCarData(String label,String macSN,String value){

        //天车类型
        String carType = macSN.substring(2);

        if(StringUtils.isEmpty(label) || label.length() < 8){
            return true;
        }
        //1.截取标签看，属于大车还是小车位置
        String positionType = label.substring(7);
        //大车位置
        if(AddTaskConstant.X_TARGET_LABEL.equals(positionType)){

            int valueInt = Integer.valueOf(value);
            //废钢跨
            if(AddTaskConstant.WASTE_STEEL_CAR_NAME.equals(carType)){
                if( valueInt < 175000 &&  valueInt > 5000){
                    return true;
                }
                return false;
            } else {
                //渣钢跨
                if( valueInt < 160000 &&  valueInt > 5000){
                    return true;
                }
                return false;
            }
        }

        //小车位置
        if(AddTaskConstant.Y_TARGET_LABEL.equals(positionType)){
            int valueInt = Integer.valueOf(value);

            //废钢跨
            if(AddTaskConstant.WASTE_STEEL_CAR_NAME.equals(carType)){
                if( valueInt < 38000 &&  valueInt > 25000){
                    return true;
                }
                return false;
            } else {
                //渣钢跨
                if( valueInt < 19000 &&  valueInt > 2000){
                    return true;
                }
                return false;
            }
        }

        return true;

    }


}
